package qc.common.core.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 通信通道类型枚举
 *
 * @author QuCheng Tech
 * @since 2024/1/24
 */
@Getter
@AllArgsConstructor
public enum CommunicationChannelTypeEnum {
    UN_DEFINE(0, "未定义"),
    NET_TCP(10, "网络TCP"),
    NET_UDP(11, "网络UDP"),
    SMS(20, "短信"),
    LINE_RS232(30, "RS232"),
    LINE_RS485(31, "RS485"),
    GPRS_TCP(40, "GPRS_TCP"),
    GPRS_UDP(41, "GPRS_UDP"),
    SATELLITE_BD(50, "北斗卫星");

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int型数值获取对应的通讯信道类型枚举
     *
     * @param index 信道类型int值
     * @return qc.common.core.enums.CommunicationChannelTypeEnum
     * @author QuCheng Tech
     * @since 2025/8/16
     */
    public static CommunicationChannelTypeEnum getCommunicationChannelTypeEnum(Integer index) {
        if (index != null && index > 0x0) {
            for (CommunicationChannelTypeEnum item : CommunicationChannelTypeEnum.values()) {
                if (item.getIndex() == index) {//判断序号使用getIndex，判断内容使用getName
                    return item;
                }
            }
        }
        return CommunicationChannelTypeEnum.UN_DEFINE;
    }
}
